'''
Created on Jan 30, 2013

@author: dheigl
'''
from fin2012.RandomizedList import RandomizedList
from fin2012.Simulation import Simulation
from fin2012.SimulationList import SimulationList
from fin2012.fetchPortfolio import GoogleQuote
import CalculateValueAtRisk
import datetime

class Start():
    '''
    classdocs
    '''
    
    _instance = None
    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = super(Start, cls).__new__(
                                cls, *args, **kwargs)
        return cls._instance
    
    def getSymbols(self):
        return self.symbols
    
    def generateData(self, count=20, future=8, startdate='2012-01-01', enddate=datetime.date.today().isoformat()):
        symbols = self.getSymbols()
        data = GoogleQuote().getData(symbols, startdate, enddate)
        CalculateValueAtRisk.calculateVAR(data)
        CalculateValueAtRisk.PrintPeriodicReturns()
        CalculateValueAtRisk.IndexPeriodicReturns()
        CalculateValueAtRisk.printList()
        print "\n"
        simList = SimulationList()
        for i in range(count):
            r = CalculateValueAtRisk.randomize(0, count)
            s = Simulation()
            s.simulate(r, future)
            simList.add(s)
            RandomizedList.rList = []
    
    def __init__(self, symbols):
        '''
        Constructor
        '''
        self.symbols = symbols
    
